package com.example.mybatiesdemo.controller;

import com.example.core.common.web.ResultBean;
import com.example.core.common.web.controller.BaseController;
import com.example.core.mybatis.service.CommonDaoService;
import com.example.example.TestTableExample;
import com.example.model.TestTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping
public class DemoController extends BaseController {

    @Autowired
    private CommonDaoService commonDaoService;
    @GetMapping("test")
    public Object test() {
        return "hello world";
    }

    @PostMapping("/test_table")
    public ResultBean  insert(@RequestBody TestTable testTable) {
        return returnSuccess(commonDaoService.insert(testTable));
    }

    @GetMapping("/test_table")
    public ResultBean  get(@RequestParam String  name) {
        TestTableExample example = new TestTableExample();
        example.and().andNameLike("%" + name +"%");
        example.orderBy("createdTime").desc();
        return returnSuccess(commonDaoService.selectByExample(example));
    }
}
